#!/bin/bash

tmp1=`mktemp`
tmp2=`mktemp`
tmp3=`mktemp`
tmp4=`mktemp`

#z="3";m="4";k="2";l="9";d="0";b="5";i="7";w="6";r="8";c="1"

wget -q -O $tmp1 \
'http://www.cnproxy.com/proxy1.html' \
'http://www.cnproxy.com/proxy2.html' \
'http://www.cnproxy.com/proxy3.html' \
'http://www.cnproxy.com/proxy4.html' \
'http://www.cnproxy.com/proxy5.html' \
'http://www.cnproxy.com/proxy6.html' \
'http://www.cnproxy.com/proxy7.html' \
'http://www.cnproxy.com/proxy8.html' \
'http://www.cnproxy.com/proxy9.html' \
'http://www.cnproxy.com/proxy10.html'


grep -o -E '<td>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}<SCRIPT type=text/javascript>document.write\([^\)]+\)' $tmp1 |\
sed -s -r -e 's/[^0-9]*([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}).*\(":"(.*)\).*/\1 \2/g' |\
sed -e 's/+//g' -e 's/c/1/g' -e 's/k/2/g' -e 's/z/3/g' -e 's/m/4/g' -e 's/b/5/g' -e 's/w/6/g' -e 's/i/7/g' -e 's/r/8/g' -e 's/l/9/g' -e 's/d/0/g' > $tmp2

./pt -n 50 -f $tmp2 > $tmp3
grep OK $tmp3 |sort -t: -k4 -h > $tmp4
cat $tmp4|grep -v CN


rm -f $tmp1 $tmp2 $tmp3 $tmp4
exit 0;


